package com.gk.panda.commons.util;

import com.gk.panda.commons.constant.Constants;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @ClassName: CodeUtils
 * @Description: TODO
 * @author: Sir.yang
 * @date: 2022/11/4 11:48
 * @version: 1.0
 **/
public class CodeUtils {

    /**
     * @description: 获取编号4位，根据年月日拼接
     * @param: [sn：初始编号, startCode：编号前缀]
     * @return: java.lang.String
     * @date: 2022/11/4 11:50
     * @version: 1.0
     **/
    public static String getCode(String sn, String startCode){
        StringBuffer code = new StringBuffer();
        code.append(startCode);
        code.append(DateUtils.parseDateToStr("yyyyMMdd", new Date()));
        Integer number = Constants.DEFU_NUM;
        if(StringUtils.isNotBlank(sn)){
            Integer num = Integer.valueOf(sn.substring(sn.length() - Constants.FORE));
            number = num + Constants.ONE;
        }
        if(number < 10){
            code.append("000" + number);
        }else if(number< 100){
            code.append("00" + number);
        }else if(number< 1000){
            code.append("0" + number);
        }else{
            code.append(number);
        }
        return code.toString();
    }
}
